package com.afollestad.materialdialogs;

import com.afollestad.materialdialogs.internal.MDRootLayout;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.CommonDialog;
import ohos.agp.window.dialog.IDialog;
import ohos.app.Context;

/**
 * @author Aidan Follestad (afollestad)
 */
class DialogBase extends CommonDialog implements IDialog {
    private static final String TAG = DialogBase.class.getSimpleName();
    protected MDRootLayout view;
    private OnShowListener showListener;
    private OnDismissListener dismissListener;
    private OnCancelListener cancelListener;

    DialogBase(Context context) {
        super(context);
    }

    final void setOnShowListener(OnShowListener listener) {
        showListener = listener;
    }

    final void setOnDismissListener(OnDismissListener listener) {
        dismissListener = listener;
    }

    final void setOnCancelListener(OnCancelListener listener) {
        cancelListener = listener;
    }

    final void setOnShowListenerInternal() {
        super.onShow();
    }

    final void setViewInternal(Component view) {
        super.setContentCustomComponent(view);
    }

    @Override
    protected void onShow() {
        super.onShow();
        if (showListener != null) {
            showListener.onDialogShown(this);
        }
    }

    @Override
    protected void onHide() {
        super.onHide();
        if (cancelListener != null && dismissListener != null) {
            cancelListener.onDialogCancel(this);
            dismissListener.onDialogDismiss(this);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (cancelListener != null && dismissListener != null) {
            cancelListener.onDialogCancel(this);
            dismissListener.onDialogDismiss(this);
        }
    }

    @Override
    public CommonDialog setContentCustomComponent(Component component) {
        return super.setContentCustomComponent(component);
    }
}
